home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 23 July 1998
- // Procedure Name: exportComposerCurves
- // Description:
- //
- //<doc>
- //<name exportComposerCurves>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<synopsis>
- // exportComposerCurves
- //
- //<description>
- // Generates a bezier curve(s) to import into Composer
- // based on a specified attribute in Maya.
- //<ol>
- // <li>Select objects with attributes to be exported
- // <li>exportComposerCurves
- // <li>select which attributes should be exported
- //</ol>
- // This will output a ".cmp" to the current maya project's
- // directory. You can File>Import this into Composer.
- //<flags>
- // none
- //
- //<returns>
- // none
- //
- //<examples>
- // select -r nurbsSphere1;
- // exportComposerCurves;
- //</doc>
- //
-
-
- global proc tvcCurve (string $attrName, int $choice)
- {
-
- // temp holder of current attribute value
-
- float $tmpVal;
- global string $name;
-
- // get names of text input fields
-
- $cmpname = `textFieldGrp -q -tx $name`;
-
- // Set up output filename to projects directory
-
- string $workspace = `workspace -q -rd`;
- $filename = ( $workspace + "/" + $cmpname );
-
- // open filename for printing
-
- if ($choice == 0)
- {
- int $fileId = fopen( $filename, "w" );
- fprint ($fileId, "#! Composer Bezier Curves Created in Maya \n");
- fclose( $fileId );
- }
-
-
- //
- // Only output curves with at least two keyframes
- //
-
- $n_keyframes = `keyframe -q -keyframeCount $attrName`;
-
- if ( $n_keyframes > 1 )
- {
- // open file again for appending
-
- int $fileId = fopen( $filename, "a" );
- fprint ($fileId, "#! " + $attrName + "\n");
-
- //
- // select the curve and turn on weighted tangents
- //
-
- selectKey -clear;
- selectKey -add -k $attrName;
- int $wt[] = `keyTangent -q -weightedTangents`;
- keyTangent -e -weightedTangents true;
-
- // this is the first part of the CardinalCurve definition
- // first break up the file name to get rid of the decimal
- // and any posible pipe symbols since Composer doesnt like them
-
- string $tmp = `substitute "|" $attrName "_"`;
- string $noPipeName = `substitute "\\." $tmp "_"`;
- fprint ($fileId, $noPipeName + " = Bezier(");
-
- // get the attr value and print it to the filename
-
- float $t[] = `keyframe -q $attrName`;
- float $v[] = `keyframe -q -vc $attrName`;
- float $inA[] = `keyTangent -q -inAngle $attrName`;
- float $outA[] = `keyTangent -q -outAngle $attrName`;
- float $inW[] = `keyTangent -q -inWeight $attrName`;
- float $outW[] = `keyTangent -q -outWeight $attrName`;
-
- for ($i = 0; $i < $n_keyframes; ++$i )
- {
- fprint ($fileId, $v[$i] + "@" + trunc($t[$i]) + "," );
- if ($i%4==0)
- {
- fprint ($fileId, "\n\t");
- }
- }
-
-
- //
- // This is the bezier identifier
- //
-
- fprint ($fileId, "50");
-
-
- //
- // Now write the tangents
- //
-
- for ($i = 0; $i < $n_keyframes; ++$i )
- {
- float $tangent[4];
-
- $tangent[0] = -cos(deg_to_rad($inA[$i])) * $inW[$i];
- $tangent[1] = -sin(deg_to_rad($inA[$i])) * $inW[$i];
- $tangent[2] = cos(deg_to_rad($outA[$i])) * $outW[$i];
- $tangent[3] = sin(deg_to_rad($outA[$i])) * $outW[$i];
-
- fprint($fileId, ",[" + $tangent[0] + "," + $tangent[1] + ","
- + $tangent[2] + "," + $tangent[3] + "]");
- if ($i%4==0)
- {
- fprint ($fileId, "\n\t");
- }
- }
-
-
- //
- // We are done
- //
-
-
- keyTangent -e -weightedTangents $wt[0];
- fprint ($fileId, ")\n");
- fclose( $fileId );
-
- // send message to script ed
- print ("// Result: Outputing " + $attrName + " to " + $filename + "\n");
- }
-
- } // end tvcCurve()
-
-
- global proc getExportAttr(string $objList, int $choice)
- {
- string $objList;
- int $choice;
- string $exportAttr[];
-
- // $choice to determine to export selected or all
-
- if ($choice == 0)
- {
- $exportAttr = `textScrollList -q -si $objList`;
- }
- else
- {
- $exportAttr = `textScrollList -q -ai $objList`;
- }
-
- if (size($exportAttr)>0)
- {
- for ($x = 0; $x < size($exportAttr); $x++)
- {
- if ($x==0)
- {
- tvcCurve $exportAttr[$x] 0;
- }
- else
- {
- tvcCurve $exportAttr[$x] 1;
- }
- }
- }
- else
- {
- error ("Export Failed. Nothing was selected.");
- }
-
- } // end getExportAttr()
-
-
- global proc updateSelected()
- {
- string $selList[] = `ls -sl`;
- string $animCurveType = "animCurveTU";
-
- // clear textScrollList
- textScrollList -e -ra "exportAttrList";
-
- for ($obj in $selList)
- {
- string $id = nodeType( $obj );
- if ( strcmp( $id, $animCurveType ) == 0 )
- {
- textScrollList -e -a $obj exportAttrList;
- }
-
- $conAttr = `listAttr -k $obj`;
- for ($attr in $conAttr)
- {
- $objAttr = ($obj + "." + $attr);
- $connected = `listConnections -d false $objAttr`;
- if (size($connected)>0)
- {
- textScrollList -e -a $objAttr exportAttrList;
- }
- }
- }
-
- } // end updateSelected()
-
-
- proc makeAttrWin (string $win)
- {
- // variable declaration for text fields
- global string $name;
-
- window -title "Composer Curve Export Tool"
- -iconName "Composer Export"
- $win;
-
- // set up text list for attributes
- formLayout composerForm;
-
- text -al "left" -l "Selected Objects With Inputs" textPrompt;
- textScrollList -w 325 -h 158 -nr 9 -ams true exportAttrList;
-
- // setup for text inputs
-
- $name = `textFieldGrp -cal 1 right -cw 1 50 -enable true -l "Name"
- -tx "MayaCurve.cmp" `;
-
- float $s = `playbackOptions -q -min`;
- float $e = `playbackOptions -q -max`;
-
- // setup for export and close buttons
-
- button -l "Export Selected"
- -c ("getExportAttr" + " exportAttrList" + " 0;" + "window -e -vis 0 " + $win )
- expSelButton;
- button -l "Export All"
- -c ("getExportAttr" + " exportAttrList" + " 1;" + "window -e -vis 0 " + $win )
- expAllButton;
- button -l "Cancel" -c ("window -e -vis 0 " + $win)
- cancelButton;
-
- formLayout -edit
- -af textPrompt "top" 5
- -af textPrompt "left" 5
- -af textPrompt "right" 5
-
- -ac exportAttrList "top" 2 textPrompt
- -af exportAttrList "left" 5
- -af exportAttrList "right" 5
- -ac exportAttrList "bottom" 5 $name
-
- -af $name "left" 5
- -af $name "right" 5
- -ac $name "bottom" 5 expSelButton
-
- -an expSelButton "top"
- -af expSelButton "left" 5
- -ap expSelButton "right" 2 33
- -af expSelButton "bottom" 5
-
- -an expAllButton "top"
- -ap expAllButton "left" 2 33
- -ap expAllButton "right" 2 66
- -af expAllButton "bottom" 5
-
- -an cancelButton "top"
- -ap cancelButton "left" 2 66
- -af cancelButton "right" 5
- -af cancelButton "bottom" 5
-
- composerForm;
-
-
- } // end makeAttrWin()
-
-
- global proc exportComposerCurves()
- {
- global int $tvcExportWindow;
- $win = "tvcCurveWin";
- if (!`window -exists $win`)
- {
- makeAttrWin ($win);
- $tvcExportWindow = `scriptJob -p $win -e "SelectionChanged"
- updateSelected`;
- updateSelected;
- }
- showWindow $win;
- }
-